package com.isoft.service.tableservice;


import com.isoft.dao.tabledao.DfmeAirlDao;
import com.isoft.entity.tableentity.dfme_airl.Arpt;
import com.isoft.entity.tableentity.dfme_airl.DfmeAirlMsg;
import com.isoft.utils.TimeFormatUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.text.ParseException;
import java.util.List;

@Slf4j
@Service
public class DfmeArilService {
    @Autowired
    private DfmeAirlDao dfmeAirlDao;
    @Transactional
    public int insertmsg(DfmeAirlMsg dfmeAirlMsg) throws ParseException {
        Timestamp create_time=TimeFormatUtils.GetNowTime();
        dfmeAirlDao.insertMeta(create_time,dfmeAirlMsg.getDfmeAirlMeta());
        dfmeAirlDao.insertDflt(dfmeAirlMsg.getDfmeAirlMeta().getSeqn(),create_time,dfmeAirlMsg.getDfmeAirlDflt());
        List<Arpt> aril=dfmeAirlMsg.getDfmeAirlDflt().getAril();

        if (null != aril && !aril.isEmpty()) {
            for (int index = 0; index < aril.size(); index++) {
                Arpt arpt = aril.get(index);
                Timestamp fptt = TimeFormatUtils.stringToTimestamp(arpt.getFptt());
                Timestamp fett = TimeFormatUtils.stringToTimestamp(arpt.getFett());
                Timestamp fplt = TimeFormatUtils.stringToTimestamp(arpt.getFplt());
                Timestamp frtt = TimeFormatUtils.stringToTimestamp(arpt.getFrtt());
                Timestamp felt = TimeFormatUtils.stringToTimestamp(arpt.getFelt());
                Timestamp frlt = TimeFormatUtils.stringToTimestamp(arpt.getFrlt());
                dfmeAirlDao.insertArpt(dfmeAirlMsg.getDfmeAirlMeta().getSeqn(),
                        fptt, fett, fplt, frtt, felt, frlt,create_time, arpt);
            }
        }
        return 1;
   }
}
